package com.example.administrator.myapplication.view.other;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.example.administrator.myapplication.R;
import com.example.administrator.myapplication.base.BaseActivity;
import com.example.administrator.myapplication.utils.WebViewUtils;

import butterknife.BindView;


/**
 * 作者　　: 杨阳
 * 创建时间: 2016/10/22 16:05
 * 邮箱　　：360621904@qq.com
 * <p>
 * 功能介绍：协议
 */

public class WebViewActivity extends BaseActivity {
    String url;
    @BindView(R.id.switchRoot)
    WebView webView;

    public static void startUI(Context context, String url) {
        Intent intent = new Intent(context, WebViewActivity.class);
        intent.putExtra(Intent.ACTION_VIEW, url);
        context.startActivity(intent);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public int getContentView() {
        return R.layout.activity_agreement;
    }


    public void parseIntent(Intent intent) {
        url = intent.getStringExtra(Intent.ACTION_VIEW);

    }


    public void initView() {
        toolbar.setTitle("网页内容");
        toolbar. setNavigationIcon(R.drawable.material_back);
        toolbar.  setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });



        WebViewUtils.configWebview(webView);


        webView.loadUrl(url);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
//                loadingAndRetryManager.showContent();
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
//                loadingAndRetryManager.showLoading(new ContextData("页面获取中"));
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                view.loadUrl(url);
                return true;
            }
        });
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        webView.reload();
    }


}
